<template>
  <div>
    <Form :model="form" ref="form" :rules="rules1">
      <Card>
        <div class="title">基本信息</div>
        <Row>
          <i-col span="4" style="text-align:right">
            <FormItem>培训主题：</FormItem>
          </i-col>
          <i-col span="5">
            <FormItem prop="theme">
              <Input v-model="form.theme" placeholder="请输入" clearable />
            </FormItem>
          </i-col>
          <i-col span="4" style="text-align:right">
            <FormItem>培训管理机构：</FormItem>
          </i-col>
          <i-col span="4">
            <FormItem prop="trainOrganization">
              <Cascader change-on-select :data="organizaitonList" class="organizaitonSelect" v-model="form.trainOrganization" placeholder="培训管理机构" clearable></Cascader>
            </FormItem>
          </i-col>
        </Row>
        <Row>
          <i-col span="4" style="text-align:right">
            <FormItem>培训内容概述：</FormItem>
          </i-col>
          <i-col span="20">
            <FormItem prop="content">
              <Input
                type="textarea"
                rows="3"
                v-model="form.content"
                placeholder="请输入"
                style="width:80%"
                clearable
                class="textarea"
              />
            </FormItem>
          </i-col>
        </Row>
        <Row>
          <i-col span="4" style="text-align:right">
            <FormItem>是否考核：</FormItem>
          </i-col>
          <i-col span="4">
            <FormItem prop="isExam">
              <Select v-model="form.isExam" placeholder="请选择" clearable transfer>
                <Option value="1">是</Option>
                <Option value="0">否</Option>
              </Select>
            </FormItem>
          </i-col>
        </Row>
        <span v-if="form.isExam === '1'">
          <div class="title">考核信息</div>
          <div class="examButton">
            <Button type="primary" @click="downloadModal">模板下载</Button>
            <!-- <Button type="primary" class="marginBoth" @click="upload">模板上传</Button> -->
            <Uploadv
              ref="upload"
              :before-upload="handleUpload"
              :show-upload-list="false"
              :on-success="uploadSuccess"
              :on-error="uploadFail"
              :headers="{
                  'Authorization':authorization,
                }"
              name="file"
              :data="{
                  trainId:trainid
                }"
              :action="action"
              style="dispaly:inline-block"
            >
              <Button type="primary" class="marginBoth">模板上传</Button>
            </Uploadv>
            <Button type="primary" @click="examTemplate" :disabled="previewDisabled">考核模板预览</Button>
            <Modal
              footer-hide="true"
              :value="templateModal"
              :mask-closable="false"
              @on-visible-change="modalVisibleChange"
              width="1000"
            >
              <span slot="header" style="color:#fff;font-size:16px">考核模板预览</span>
              <div style="max-height:400px;overflow:auto">
                <span v-if="radioGroup">
                  <div class="title">单选题</div>
                  <div class="question" v-for="(item,index) in radioGroup" :key="index">
                    <div class="questionTitle">{{index+1}}.{{item.questiondetail}}</div>
                    <RadioGroup vertical style="padding-left:20px">
                      <Radio label="1" v-if="item.a">
                        <span class="questionOption">A.{{item.a}}</span>
                      </Radio>
                      <Radio label="2" v-if="item.b">
                        <span class="questionOption">B.{{item.b}}</span>
                      </Radio>
                      <Radio label="3" v-if="item.c">
                        <span class="questionOption">C.{{item.c}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.d">
                        <span class="questionOption">D.{{item.d}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.e">
                        <span class="questionOption">E.{{item.e}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.f">
                        <span class="questionOption">F.{{item.f}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.g">
                        <span class="questionOption">G.{{item.g}}</span>
                      </Radio>
                    </RadioGroup>
                  </div>
                </span>
                <span v-if="multipleGroup">
                  <div class="title">多选题</div>
                  <div class="question" v-for="(item,index) in multipleGroup" :key="index">
                    <div class="questionTitle">{{index+1}}.{{item.questiondetail}}</div>
                    <CheckboxGroup style="padding-left:20px">
                      <Checkbox label="1" v-if="item.a">
                        <span class="questionOption">A.{{item.a}}</span>
                      </Checkbox>
                      <br />
                      <Checkbox label="2" v-if="item.b">
                        <span class="questionOption">B.{{item.b}}</span>
                      </Checkbox>
                      <br />
                      <Checkbox label="3" v-if="item.c">
                        <span class="questionOption">C.{{item.c}}</span>
                      </Checkbox>
                      <br />
                      <Checkbox label="4" v-if="item.d">
                        <span class="questionOption">D.{{item.d}}</span>
                      </Checkbox>
                      <br />
                      <Checkbox label="5" v-if="item.e">
                        <span class="questionOption">E.{{item.e}}</span>
                      </Checkbox>
                      <br />
                      <Checkbox label="6" v-if="item.f">
                        <span class="questionOption">F.{{item.f}}</span>
                      </Checkbox>
                      <br />
                      <Checkbox label="7" v-if="item.g">
                        <span class="questionOption">G.{{item.g}}</span>
                      </Checkbox>
                    </CheckboxGroup>
                  </div>
                </span>
                <span v-if="judgeGroup">
                  <div class="title">判断题</div>
                  <div class="question" v-for="(item,index) in judgeGroup" :key="index">
                    <div class="questionTitle">{{index+1}}.{{item.questiondetail}}</div>
                    <RadioGroup vertical style="padding-left:20px">
                      <Radio label="1" v-if="item.a">
                        <span class="questionOption">A.{{item.a}}</span>
                      </Radio>
                      <Radio label="2" v-if="item.b">
                        <span class="questionOption">B.{{item.b}}</span>
                      </Radio>
                      <Radio label="3" v-if="item.c">
                        <span class="questionOption">C.{{item.c}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.d">
                        <span class="questionOption">D.{{item.d}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.e">
                        <span class="questionOption">E.{{item.e}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.f">
                        <span class="questionOption">F.{{item.f}}</span>
                      </Radio>
                      <Radio label="4" v-if="item.g">
                        <span class="questionOption">G.{{item.g}}</span>
                      </Radio>
                    </RadioGroup>
                  </div>
                </span>
              </div>
            </Modal>
          </div>
          <Row style="margin-top:20px;margin-left:20px;">
            <i-col span="13" v-if="!previewDisabled">
              <FormItem>
                <span style="margin-right:20px">共计：{{examDetail?examDetail.allquestions:''}}道题</span>
                单选题：{{examDetail?examDetail.single:''}}道 多选题：{{examDetail?examDetail.multiple:''}}道 判断题：{{examDetail?examDetail.judge:''}}道
                <span
                  class="marginBoth"
                >考核总分：{{examDetail?examDetail.socre:''}}分</span>
              </FormItem>
            </i-col>
            <i-col span="10">
              <Row>
                <i-col span="5" style="line-height:35px">及格分数线：</i-col>
                <i-col span="19">
                  <FormItem prop="examPassMark">
                    <Input v-model="form.examPassMark" style="width:30%" placeholder="请输入分数" />
                  </FormItem>
                </i-col>
              </Row>
            </i-col>
          </Row>
          <Row style="margin-left:20px;">
            <i-col span="2">
              <FormItem>答题起止期：</FormItem>
            </i-col>
            <i-col span="10">
              <FormItem prop="answerDateRange">
                <DatePicker
                  type="daterange"
                  style="width:60%"
                  v-model="form.answerDateRange"
                  :editable="false"
                  :options="options3"
                  clearable
                  transfer
                  placeholder="开始时间 ~ 结束时间"
                ></DatePicker>
              </FormItem>
            </i-col>
          </Row>
        </span>
        <Row gutter="50">
          <i-col span="12">
            <div class="title">培训人员选择</div>
            <Row class="organizaiton">
              <div class="organizaitonTitle">人员选择</div>
              <Row gutter="40">
                <i-col span="20">
                  <FormItem>
                    <Cascader change-on-select :data="organizaitonList" class="organizaitonSelect" v-model="form.organization" placeholder="培训管理机构" clearable></Cascader>
                  </FormItem>
                </i-col>
                <i-col span="4">
                  <Button type="primary" @click="organizaitonChange">查询</Button>
                </i-col>
              </Row>
            </Row>
            <div class="transferContent">

              <!-- <Row gutter="10">
                <i-col span="8">
                <Select v-model="locationName" filterable @on-change="locationNameChange()">
                  <Option v-for="item in locationNameList" :value="item.name" :key="item.name">{{ item.name }}</Option>
                </Select>
                <div style="height:177px;overflow:auto;border:1px solid #ccc;padding:3px;">
                  <div v-for="(item, index) in dataPeople" :key="index">
                    <div>
                      <span :class="item.showChild===true ? 'rot' : ''" style="padding-right:5px;">
                        <Icon type="ios-arrow-forward" @click="changeShowState(index)" />
                      </span>
                      {{item.name}}
                    </div>
                    <div v-if="item.showChild">
                      <div style="margin-left:20px;" v-for="(inner,ind) in item.children" :key="'inner'+inner.name" @click="getDetail(inner.name,index,ind)"><span :class="((fatherInd==index&&childInd==ind) || locationName == inner.name) ? 'highlight' : ''">{{inner.name}}</span></div>

                    </div>

                  </div>
                </div>
                </i-col>
                <i-col span="16">
                  <Transfer
                    :data="transferData"
                    :target-keys="targetKeys"
                    :render-format="renderFormat"
                    :titles="transferTitle"
                    @on-change="handleChange"
                  ></Transfer>
                </i-col>
              </Row> -->
              <Transfer
                :data="transferData"
                :target-keys="targetKeys"
                :render-format="renderFormat"
                :titles="transferTitle"
                @on-change="handleChange"
              ></Transfer>
            </div>
            <div class="personFoot">
              <Button type="primary" @click="handleSubmit" :loading="submitLoading">保存</Button>
            </div>
          </i-col>
          <i-col span="12">
            <div class="title">相关文件</div>
            <List border class="fileList">
              <div slot="header" class="fileContent">
                <span>文件名称</span>
                <span class="headerOperate">操作</span>
              </div>
              <ListItem v-for="(item,index) in fileCopy" :key="index">
                <ListItemMeta v-if="index < 6">
                  <span slot="description" style="color:#000">{{item.name}}</span>
                </ListItemMeta>
                <template slot="action" v-if="index < 6">
                  <li>
                    <span
                      style="color:rgba(24, 144, 255, 1);cursor:pointer"
                      @click="delectFile2(item.keyID)"
                    >删除</span>
                  </li>
                </template>
              </ListItem>
            </List>
            <div class="fileFoot">
              <Uploadv
                ref="upload2"
                :before-upload="handleUpload2"
                :show-upload-list="false"
                :on-success="uploadSuccess2"
                :on-error="uploadFail2"
                :format="['pdf','mp4']"
                :on-format-error="handleFormatError"
                :headers="{
                  'Authorization':authorization,
                }"
                name="file"
                :data="{
                  trainid:trainid
                }"
                :action="action1"
                style="dispaly:inline-block"
              >
                <Button type="primary" style="margin-right:20px;">上传</Button>
              </Uploadv>
              <Page
                :total="total"
                @on-change="pageChange"
                :page-size="pageSize"
                :current="pageIndex"
                transfer
              ></Page>
            </div>
            <Button @click="cancel">取消</Button>
          </i-col>
        </Row>
      </Card>
    </Form>
  </div>
</template>

<script>
import {exportFile} from "../../../util/util"
import util from "../../../util/util";
export default {
  data() {
    const validateDate = (rule, value, callback) => {
      if (value[0]) {
      } else {
        callback(new Error("答题起止期不能为空"));
      }
      callback();
    };
    const validateGrade = (rule, value, callback) => {
      let reg = /^[0-9]*$/;
      if (value && !reg.test(value)) {
        callback(new Error("请输入正整数"));
      }
      if (this.examDetail) {
        if (value && value <= this.examDetail.socre) {
        } else {
          console.log(value, this.examDetail, value <= this.examDetail.socre);
          callback(new Error("及格分数不能大于总分"));
        }
      } else {
        callback(new Error("总分不能为空"));
      }
      callback();
    };
    return {
      options3: {
        disabledDate(date) {
          return date && date.valueOf() < Date.now() - 86400000;
        }
      },
      mark: this.$route.query.mark,
      obj: this.$route.query.obj,
      // 表单信息
      form: {
        theme: "",
        content: "",
        isExam: "",
        organization: "",
        trainOrganization: "",
        examPassMark: "",
        answerDateRange: ["", ""]
      },
      organizaitonList: [],
      // 校验
      rules1: {
        theme: [{ required: true, message: "培训主题不能为空" }],
        content: [{ required: true, message: "培训内容概述不能为空" }],
        isExam: [{ required: true, message: "是否考核不能为空" }],
        examPassMark: [
          { required: true, message: "及格分数线不能为空" },
          { validator: validateGrade, trigger: "blur" }
        ],
        answerDateRange: [{ validator: validateDate, trigger: "blur" }],
        trainOrganization: [{ required: true, message: "培训管理机构不能为空" }]
      },
      // 穿梭框数据
      transferData: [
        // { key: "1", label: "Content 1" },
        // { key: "2", label: "Content 2" },
        // { key: "3", label: "Content 3" }
      ],
      selectData: [],
      targetKeys: [
        // "1", "2"
      ],
      transferTitle: ["未添加成员", "已有成员"],
      // 分页数据
      total: 0,
      pageIndex: 1,
      pageSize: 6,
      file: [],
      fileCopy: [],
      fileIndex: 0,
      authorization: "",
      action: "",
      action1: "",
      trainid: "",
      examDetail: "",
      previewDisabled: true,
      submitLoading: false,
      templateModal: false,
      radioGroup: "",
      multipleGroup: "",
      judgeGroup: "",
      locationNameList:[
        {name:"续期协管员"},
        {name:"见习续期服务专员"},
        {name:"初级续期服务专员一级"},
        {name:"初级续期服务专员二级"},
        {name:"中级续期服务专员一级"},
        {name:"中级续期服务专员二级"},
        {name:"高级续期服务专员一级"},
        {name:"高级续期服务专员二级"},
        {name:"高级续期服务专员三级"},
        {name:"资深续期服务专员一级"},
        {name:"资深续期服务专员二级"},
        {name:"见习续收组主任"},
        {name:"初级续收组主任一级"},
        {name:"初级续收组主任二级"},
        {name:"中级续收组主任一级"},
        {name:"中级续收组主任二级"},
        {name:"高级续收组主任一级"},
        {name:"高级续收组主任二级"},
        {name:"续收部经理"},
        {name:"总公司内勤"},
        {name:"省公司内勤"},
        {name:"市公司内勤"},
      ],
      dataPeople:[
        {
          name:"续期协管员",
          showChild: false,
          children:[
            {name:"续期协管员"},
          ]
        },
        {
          showChild: false,
          name:"续期服务专员",
          children:[
            {name:"见习续期服务专员"},
            {name:"初级续期服务专员一级"},
            {name:"初级续期服务专员二级"},
            {name:"中级续期服务专员一级"},
            {name:"中级续期服务专员二级"},
            {name:"高级续期服务专员一级"},
            {name:"高级续期服务专员二级"},
            {name:"高级续期服务专员三级"},
            {name:"资深续期服务专员一级"},
            {name:"资深续期服务专员二级"},
          ]
        },
        {
          showChild: false,
          name:"续收外勤主任",
          children:[
            {name:"见习续收组主任"},
            {name:"初级续收组主任一级"},
            {name:"初级续收组主任二级"},
            {name:"中级续收组主任一级"},
            {name:"中级续收组主任二级"},
            {name:"高级续收组主任一级"},
            {name:"高级续收组主任二级"},
          ]
        },
        {
          showChild: false,
          name:"续收经理",
          children:[
            {name:"续收部经理"},
          ]
        },
        {
          showChild: false,
          name:"内勤",
          children:[
            {name:"总公司内勤"},
            {name:"省公司内勤"},
            {name:"市公司内勤"},
          ]
        },
      ],
    };
  },
  methods: {
    //选择人员输入
    locationName(){
      this.locationName
    },
    //选择二级人员
    getDetail(name,fatherInd,ind){
      this.fatherInd = fatherInd;
      this.childInd = ind;
      this.locationName = name
      this.dataPeople.splice(1000,0)
      this.$forceUpdate();
      //之后这边加查询操作
    },
    //人员展示下拉
    changeShowState(index){
      this.dataPeople[index].showChild = !this.dataPeople[index].showChild;
      this.$forceUpdate();
    },

    // 弹窗关闭
    modalVisibleChange(value) {
      if (!value) {
        this.templateModal = false;
      }
    },

    // 机构改变，右边框值不变
    organizaitonChange() {
      if (this.submitLoading === false) {
        if (this.form.organization === undefined) {
          this.transferData = [];
          this.transferData = this.selectData;
          this.selectData.forEach(element => {
            this.targetKeys.push(element.key);
          });
        } else {
          this.api
            .selectTrainRelaAegnt({ managecom: this.form.organization[this.form.organization.length-1] })
            .then(res => {
              if (res.code == 200 && res.data != null) {
                this.transferData = res.data;
                // 添加label
                this.transferData.forEach(element => {
                  element.label = element.value;
                });
                // 将已选择人员添加查询的数据中
                this.selectData.forEach(selectElement => {
                  let index = 0;
                  this.transferData.forEach(element => {
                    if (element.key == selectElement.key) {
                      index++;
                    } else {
                    }
                  });
                  if (index === 0) {
                    this.transferData.push(selectElement);
                  }
                });
                this.targetKeys = [];
                // 将已经选择的数据展示
                this.selectData.forEach(element => {
                  this.targetKeys.push(element.key);
                });
              } else {
                this.transferData = this.selectData;
              }
            });
        }
      } else {
        this.$Message.info("不可进行此操作");
      }
    },

    // 穿梭框方法
    renderFormat(item) {
      return item.label;
    },

    // 右侧key，移动方向，新添加的key
    handleChange(newTargetKeys, direction, moveKeys) {
      console.log(newTargetKeys, direction, moveKeys,this.transferData);
      if (this.submitLoading === false) {
        if (direction === "right") {
          moveKeys.forEach(idElement => {
            this.transferData.forEach(element => {
              if (element.key == idElement) {
                this.selectData.push(element);
              }
            });
          });
        }
        if (direction === "left") {
          moveKeys.forEach(idElement => {
            this.selectData = this.selectData.filter(element => {
              return element.key != idElement;
            });
          });
        }
        this.targetKeys = newTargetKeys;
      } else {
        this.$Message.info("不可进行此操作");
      }
    },

    // 保存
    handleSubmit() {
      this.submitLoading = true;
      this.$refs.form.validate(valid => {
        if (valid) {
          if (this.selectData.length > 0) {
            this.upload2();
          } else {
            this.submitLoading = false;
            this.$Message.info("培训人员不能为空");
          }
        } else {
          this.submitLoading = false;
          this.$Message.info("信息填写有误");
        }
      });
    },

    // 分页设置
    pageChange(pageIndex) {
      this.pageIndex = pageIndex;
      let temp = [];
      let i = (pageIndex - 1) * 6;
      temp = this.file.slice(i, i + 6);
      this.fileCopy = temp;
    },

    // 取消按钮返回
    cancel() {
      if (this.submitLoading === false) {
        this.$router.go(-1);
      } else {
        this.$Message.info("不可进行此操作");
      }
    },

    // 跳到考核模板预览界面
    examTemplate() {
      this.templateModal = true;
      this.api.selectTrainTemplate({ trainid: this.trainid }).then(res => {
        if (res.code == 200 && res.data != null) {
          if (
            res.data.uerTrainQuestionOneVO &&
            res.data.uerTrainQuestionOneVO.length > 0
          ) {
            this.radioGroup = res.data.uerTrainQuestionOneVO;
          }
          if (
            res.data.uerTrainQuestionMoreVO &&
            res.data.uerTrainQuestionMoreVO.length > 0
          ) {
            this.multipleGroup = res.data.uerTrainQuestionMoreVO;
          }
          if (
            res.data.uerTrainQuestionJudgeVO &&
            res.data.uerTrainQuestionJudgeVO.length > 0
          ) {
            this.judgeGroup = res.data.uerTrainQuestionJudgeVO;
          }
        }
      });
      // if (util.dateToISOString(this.form.answerDateRange[0])) {
      //   this.form.answerDateRange[0] = util
      //     .dateToISOString(this.form.answerDateRange[0])
      //     .substr(0, 10);
      //   this.form.answerDateRange[1] = util
      //     .dateToISOString(this.form.answerDateRange[1])
      //     .substr(0, 10);
      // }
      // console.log(this.form);
      // let obj = {
      //   trainid: this.trainid,
      //   form: this.form,
      //   selectData: this.selectData,
      //   file: this.file
      // };
      // this.$router.replace({
      //   name: "examTemplate",
      //   query: {
      //     trainid: this.trainid,
      //     obj: obj
      //   }
      // });
    },

    handleUpload(file) {
      //console.log(file);
    },

    // 文件上传成功
    uploadSuccess(response, file, fileList) {
      if (response.code == 200) {
        this.$Message.info("模板上传成功");
        this.api.selectQuestionandscore({ trainid: this.trainid }).then(res => {
          this.previewDisabled = false;
          if (res.code == 200 && res.data != null) {
            this.examDetail = res.data;
            // 校验及格分数
            this.$refs.form.validateField("examPassMark");
          }
        });
      } else {
        if (response.data && response.data.error) {
          response.data.error.forEach(element => {
            response.msg += `${element};`;
          });
        }
        this.$Message.info({
          content: response.msg,
          duration: 10,
          closable: true
        });
      }
    },

    // 导入失败
    uploadFail(error, file, fileList) {
      this.$Message.info("导入失败！");
    },

    // 上传文件转到手动提交
    handleUpload2(file) {
      // 保存需要上传的文件
      let keyID = Math.random()
        .toString()
        .substr(2);
      file["keyID"] = keyID;
      this.file.push(file);
      this.total = this.file.length;
      this.pageChange(this.pageIndex);
      console.log(this.file);

      //加个校验，文件名不能重复
      //最后一个文件的文件名
      if(this.file.length){
        let len = this.file.length-1;
        console.log(this.file[len]);
        console.log(this.file[len].name)

        let lastName = this.file[len].name;
        for(let i=0;i<len;i++){
          if(this.file[i].name == lastName){
            console.log(this.file[i].name,lastName)
            this.file.splice(len,1);
            this.pageChange(this.pageIndex)
            console.log(this.file)
            this.$Message.info("存在相同的文件，请检查！");
          }

        }
      }

      return false;
    },

    // 格式错误
    handleFormatError(file) {
      this.submitLoading = false;
      this.$Message.info(
        "文件格式错误" + file.name + " 格式错误, 请选择格式为pdf或MP4"
      );
    },

    // 删除文件
    delectFile2(keyID) {
      // 删除文件
      this.file = this.file.filter(item => {
        return item.keyID != keyID;
      });
      this.fileCopy = this.fileCopy.filter(item => {
        return item.keyID != keyID;
      });
      this.pageChange(this.pageIndex);
    },

    // 上传文件
    upload2() {
      // 上传文件
      if (this.file.length != 0) {
        for (let i = 0; i < this.file.length; i++) {
          this.fileIndex = 0;
          let item = this.file[i];
          this.$refs.upload2.post(item);
        }
      } else {
        this.saveTrain();
      }
    },

    // 连接到后端
    uploadSuccess2(response, file, fileList) {
      this.fileIndex++;
      this.$Message.info(
        response.data
          ? response.data[0].filename + response.msg
          : "" + response.msg
      );
      if (this.fileIndex === this.file.length) {
        this.saveTrain();
      }
    },

    // 连不到后端的情况
    uploadFail2(response, file, fileList) {
      this.submitLoading = false;
      this.$Message.info("保存失败");
    },

    saveTrain() {
      let obj = {
        agentcodeList: this.targetKeys ? this.targetKeys + "" : null,
        startdate: util.dateToISOString(this.form.answerDateRange[0]),
        enddate: util.dateToISOString(this.form.answerDateRange[1]),
        managecom: this.form.trainOrganization
          ? this.form.trainOrganization[this.form.trainOrganization.length-1]
          : null,
        passscore: this.form.examPassMark ? this.form.examPassMark : null,
        remark: this.form.content ? this.form.content : null,
        theme: this.form.theme ? this.form.theme : null,
        totalscore: this.examDetail ? this.examDetail.socre : null,
        trainflag: this.form.isExam ? this.form.isExam : null,
        trainid: this.trainid ? this.trainid : null
      };
      this.api.insertUerTrain(obj).then(res => {
        this.submitLoading = false;
        if (res.code == 200 && res.data != null) {
          this.$Message.info("保存成功");
          this.$router.go(-1);
        } else {
          this.$Message.info(res.msg);
        }
      });
    },

    // 初始化
    initial() {
      this.authorization = sessionStorage.getItem("credentials");
      // 模板上传地址
      this.action =
        // sessionStorage.getItem("userIp") + "api/fileupload/saveTrain";
        "/scrm-gateway/scrm-uer/api/fileupload/saveTrain";
      // 文件上传地址
      // this.action1 = sessionStorage.getItem("userIp") + "api/fileupload/upload";
      this.action1 = "/scrm-gateway/scrm-uer/api/fileupload/upload";
      // 考核模板预览返回
      if (this.mark && this.mark === "back") {
        this.form.isExam = "1";
        this.trainid = this.obj.trainid;
        this.form = this.obj.form;
        if (this.obj.selectData.length > 0) {
          this.selectData = this.obj.selectData;
          this.transferData = this.selectData;
          this.selectData.forEach(element => {
            this.targetKeys.push(element.key);
          });
        }
        this.file = this.obj.file;
        console.log(this.file);
        this.pageChange(1);
        this.previewDisabled = false;
        this.api.selectQuestionandscore({ trainid: this.trainid }).then(res => {
          this.previewDisabled = false;
          if (res.code == 200 && res.data != null) {
            this.examDetail = res.data;
          }
        });
      } else {
        // 生成业务主键
        this.api.getTrainid().then(res => {
          if (res.code == 200 && res.data != null) {
            this.trainid = res.data;
          }
        });
      }
      // 下拉框
      // this.api.organizationDict().then(res => {
      //   if (res.code == 200 && res.data != null) {
      //     this.organizaitonList = res.data[0].listKeyValueVOS;
      //   }
      // });
      this.api.remanagecomList().then(res => {
        if (res.code == 200 && res.data != null) {
          let arr = []
          arr.push(res.data)
          arr.forEach(one=>{
            one.value = one.comcode
            one.label = one.comcode + '-' + one.name
            one.children = one.chilDren || []
            if (one.children) {
              one.chilDren.forEach(two=>{
                two.value = two.comcode
                two.label = two.comcode + '-' + two.name
                two.children = two.chilDren || []
                if (two.children) {
                  two.children.forEach(three=>{
                    three.value = three.comcode
                    three.label = three.comcode + '-' + three.name
                    three.children = three.chilDren || []
                    if (three.children) {
                      three.children.forEach(four=>{
                        four.value = four.comcode
                        four.label = four.comcode + '-' + four.name
                        four.children = four.chilDren || []
                      })
                    }
                  })
                }
              })
            }
          })
          console.log(arr);
          this.organizaitonList = arr
        } else {
          this.organizaitonList = [];
        }
      });
    },

    // 下载模板
    downloadModal() {
      let url = "../rest/fileDownload/downloadTrainExcel";
      // window.open(url);
      exportFile("scrm-gateway/scrm-uer/api/fileDownload/downloadTrainExcel")
    }
  },
  mounted() {
    this.initial();
    this.pageChange(1);
  },
  beforeDestroy() {
    this.options3 = null;
    this.mark = null;
    this.obj = null;
    this.form = null;
    this.organizaitonList = null;
      // 校验
    this.rules1 = null;
      // 穿梭框数据
    this.transferData = null;
    this.selectData = null;
    this.targetKeys = null;
    this.transferTitle = null;
    this.total = null;
    this.pageIndex = null;
    this.pageSize = null;
    this.file = null;
    this.fileCopy = null;
    this.fileIndex = null;
    this.authorization = null;
    this.action = null;
    this.action1 = null;
    this.trainid = null;
    this.examDetail = null;
    this.previewDisabled = null;
    this.submitLoading = null;
    this.templateModal = null;
    this.radioGroup = null;
    this.multipleGroup = null;
    this.judgeGroup = null;
    this.locationNameList = null;
    this.dataPeople = null;
  }
};
</script>

<style scoped lang="less">
@import "./index";
</style>

<style scoped>
.fileList{
  height: 295px;
}
.ivu-card{
  width: 100%;
}
textarea {
  resize: none;
}
.ivu-upload-drag,
.ivu-upload-drag:hover {
  border: none;
}
.ivu-list-bordered .ivu-list-header {
  background-color: rgba(24, 144, 255, 0.04);
  padding: 0px;
}
.ivu-transfer-list{
  /* width:152px; */
}
.rot i{
  transform: rotate(90deg);
  transition-duration: 0.3s;
}
.highlight{
  background: #21a9f8;
}
</style>
